package com.lemon.controller;
import com.lemon.domain.LogisticsCompany;
import com.lemon.domain.PageResult;
import com.lemon.domain.Result;
import com.lemon.domain.vo.LogisticsCompanyVo;
import com.lemon.service.LogisticsCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
* 物流公司表(tb_logistics_company)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/logisticsCompany")
public class LogisticsCompanyController {

    @Autowired
    private LogisticsCompanyService logisticsCompanyService;


    @GetMapping("/list")
    public Result getAllList(){
        List<LogisticsCompanyVo> list =  logisticsCompanyService.getList();
        return Result.success(list);
    }

    @GetMapping
    public Result getPage(Integer page,Integer pageSize,String companyName){
        PageResult pageResult = logisticsCompanyService.getPage(page, pageSize, companyName);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result add(@RequestBody LogisticsCompany logisticsCompany){
        logisticsCompany.setCreateTime(LocalDateTime.now());
        boolean save = logisticsCompanyService.save(logisticsCompany);
        return save?Result.success():Result.error("添加失败");
    }

    @PutMapping
    public Result update(@RequestBody LogisticsCompany logisticsCompany){
        logisticsCompany.setUpdateTime(LocalDateTime.now());
        return logisticsCompanyService.updateById(logisticsCompany)?Result.success():Result.error("修改失败");
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        return logisticsCompanyService.removeById(id)?Result.success():Result.error("删除失败");
    }

}
